package com.eeepay.eeepay_v2.enc;


import com.eeepay.eeepay_v2.app.MyApplication;
import com.eeepay.v2_library.log.LogUtils;

public class EncRSA {

	public static String EncPass(String source) throws Exception

	{

		LogUtils.d("公钥加密——私钥解密");
		LogUtils.d("\r加密前文字：\r\n" + source);
		// publicKey = Session.getSession().getEnv().get("loginPubkeys");
		LogUtils.d("\r加密公钥：\r\n" + MyApplication.publicKey);
		byte[] data = source.getBytes();
		byte[] encodedData = RSAUtils.encryptByPublicKey(data, MyApplication.publicKey);

		LogUtils.d("加密后文字：\r\n" + RSAUtils.hexString(encodedData));
		// byte[] decodedData = RSAUtils.decryptByPrivateKey(encodedData,
		// privateKey);
		// String target = new String(decodedData);
		// LogUtils.d("解密后文字: \r\n" + target);
		return RSAUtils.hexString(encodedData);
	}

	public static String EncPassByte(byte[] source) throws Exception

	{
		LogUtils.d("公钥加密——私钥解密");
		LogUtils.d("\r加密前文字：\r\n" + source);
		// publicKey = Session.getSession().getEnv().get("loginPubkeys");
		LogUtils.d("\r加密公钥：\r\n" + MyApplication.publicKey);
		byte[] encodedData = RSAUtils.encryptByPublicKey(source, MyApplication.publicKey);

		LogUtils.d("加密后文字：\r\n" + RSAUtils.hexString(encodedData));
		// byte[] decodedData = RSAUtils.decryptByPrivateKey(encodedData,
		// privateKey);
		// String target = new String(decodedData);
		// LogUtils.d("解密后文字: \r\n" + target);
		return RSAUtils.hexString(encodedData);
	}

	/**
	 * 
	 * @param source
	 *            加密字符
	 * @param pubkey
	 *            加密公钥
	 * @return
	 * @throws Exception
	 */
	public static String EncPass(String source, String pubkey) throws Exception

	{
		LogUtils.d("公钥加密——私钥解密");
		LogUtils.d("\r加密前文字：\r\n" + source);
		LogUtils.d("\r加密公钥：\r\n" + pubkey);
		byte[] data = source.getBytes();
		byte[] encodedData = RSAUtils.encryptByPublicKey(data, pubkey);

		LogUtils.d("加密后文字：\r\n" + RSAUtils.hexString(encodedData));
		// byte[] decodedData = RSAUtils.decryptByPrivateKey(encodedData,
		// privateKey);
		// String target = new String(decodedData);
		// LogUtils.d("解密后文字: \r\n" + target);
		return RSAUtils.hexString(encodedData);
	}

}
